﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HNQXYJ.Model;
using HNQXYJ.BLL;


namespace HNQXYJ.HN_Terminal
{
    public partial class TerminalMgt : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DataBind(1);
            }
        }

        protected void PrePage_Click(object sender, EventArgs e)
        {
            int currPage = Convert.ToInt32(this.LbPageNumber.Text);
            currPage--;
            if (currPage < 1)
            {
                currPage = 1;
            }
            this.txtPageNumber.Text = currPage.ToString();
            this.LbPageNumber.Text = currPage.ToString();
            this.DataBind(currPage);
        }

        protected void NextPage_Click(object sender, EventArgs e)
        {
            int currPage = Convert.ToInt32(this.LbPageNumber.Text);
            currPage++;
            if (currPage > Convert.ToInt32(this.LbPageCount.Text))
            {
                currPage = Convert.ToInt32(this.LbPageCount.Text);
            }
            this.txtPageNumber.Text = currPage.ToString();
            this.LbPageNumber.Text = currPage.ToString();
            this.DataBind(currPage);
        }

        protected void BtnGo_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                int pageCount=Convert.ToInt32(this.LbPageCount.Text);
                int pageIndex = Convert.ToInt32(this.txtPageNumber.Text.Trim());
                if (pageIndex > pageCount)
                {
                    pageIndex = pageCount;


                }
                if (pageIndex < 1)
                {
                    pageIndex = 1;
                }
                this.LbPageNumber.Text = pageIndex.ToString();
                this.txtPageNumber.Text = pageIndex.ToString();
                this.DataBind(pageIndex);
            }
        }

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            DataBind(1);
        }

        private void DataBind(int pageIndex)
        {
            int rowCount = 0;
            int pageCount = 0;
            string strWhere = "%"+this.txtTownName.Text.Trim()+"%";
           
            List<Terminal> list = TerminalBLL.TerminalPagingList(pageIndex,20,strWhere,out rowCount,out pageCount);
            if (list != null)
            {
                this.RpList.DataSource = list;
                this.RpList.DataBind();
                this.LbPageCount.Text = pageCount.ToString();
            }
        }
    }
}